package edu.kit.csl.pisa.training;

/*
This file is part of the PISA Alignment Tool.

Copyright (C) 2013
Karlsruhe Institute of Technology
Cognitive Systems Lab (CSL)
Felix Stahlberg

PISA is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PISA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PISA. If not, see <http://www.gnu.org/licenses/>.
*/

import edu.kit.csl.pisa.datatypes.SentenceAlignment;
import edu.kit.csl.pisa.datatypes.SentencePair;
import edu.kit.csl.pisa.models.AlignmentModel;

/**
 * This successor strategy is designed to implement memory efficient training.
 * Only the best alignment is taken to initialize the population in the next
 * EM iteration. Open slots are filled up with random alignments. This 
 * successor strategy ignores the legacySize parameter.
 */
public class ViterbiSuccessorStrategy extends SuccessorStrategy {

	/**
	 * Calls the super class constructor.
	 * 
	 * @param model not used in this strategy
	 */
	public ViterbiSuccessorStrategy(AlignmentModel model) {
		super(model);
	}

	/**
	 * Takes just the Viterbi alignment and discards all others. 
	 * {@inheritDoc}
	 */
	@Override
	public void findSuccessors(SentencePair senPair) 
			throws UnsupportedOperationException {
		SentenceAlignment viterbi = senPair.getViterbiAlignment();
		senPair.removeAllAlignments();
		senPair.addAlignment(viterbi.getAlignment(), viterbi.getScore());
	}
}

